import service from './service'

export const registerAPI = async (params: {
  username: string
  email: string
  password: string
  role: string
  phone: string
}) => {
  return await service.post('/auth/register', params)
}

export const loginAPI = async (email: string, password: string) => {
  return await service.post('/auth/login', {
    email,
    password,
  })
}

export const refreshAuthAPI = async (refresh_token: string) => {
  return await service.post('/auth/refresh', {
    refresh_token,
  })
}

export const logoutAPI = async () => {
  return await service.post('/auth/logout')
}

export const getMessageAPI = async () => {
  return await service.get('/users/me')
}

export const refreshUserInfoAPI = async (params: {
  nickname: string
  avatar: string
  phone: string
  bio: string
}) => {
  return await service.put('/users/me', params)
}

export const modPasswordAPI = async (old_password: string, new_password: string) => {
  return await service.put('/users/me/password', {
    old_password,
    new_password,
  })
}

export const getUserDetailAPI = async (id: number) => {
  return await service.get(`/users/${id}`)
}

//撤回申请
export const withdrawApplyAPI = async (id: number) => {
  return await service.delete(`/applications/${id}`)
}

export const getMyApplyAPI = async () => {
  return await service.get('/applications/my')
}

export const getMatchListAPI = async () => {
  return await service.get('/matches')
}

export const getMyMatchAPI = async () => {
  return await service.get('/matches/my')
}

export const confirmMatchAPI = async (id: number) => {
  return await service.post(`/matches/${id}/confirm`)
}

export const getNotificationAPI = async () => {
  return await service.get('/notifications')
}

export const getUnreadNotificationCountAPI = async () => {
  return await service.get('/notifications/unread/count')
}

export const changeToReadAPI = async (id: number) => {
  return await service.put(`/notifications/${id}/read`)
}
